package metagen;



import java.util.Random;

import main.MetaGen;

public class Opt implements MetaGen {

    private Random rand;
    private MetaGen meta;

    public Opt(MetaGen meta) {
        if (meta == null) {
            throw new RuntimeException("Regexp must be non-null!");
        }
        this.meta = meta;
        this.rand = new Random();
    }

    public String toString() {
        return meta.toString() + "?";
    }

    public String randGen() {
        if (rand.nextBoolean()) {
            return meta.randGen();
        } else {
            return "";
        }
    }

}
